package com.woniuxy.util;

import com.woniuxy.constant.JedisConstant;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author: linKe
 * @Date: 2022/1/5 10:18
 * @FileName: JedisUtil
 * @version: 1.0
 * @Description: Jedis工具类对象获取
 */
public class JedisUtil  {
    /**
     * jedis 连接池
     */
    private static JedisPool jedisPool;

    static {
        //System.out.println(JedisConstant.HOST);
        GenericObjectPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(50);
        poolConfig.setMaxIdle(10);
        jedisPool = new JedisPool(poolConfig, JedisConstant.HOST, 6379, 2000);
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
